package testpackage;

import java.util.regex.Pattern;

public class TrafficBean {

	private String appid;
	private String street;
	private String city;
	private String state;
	private String zip;
	private String location;
	private Float latitude;
	private Float longtitude;
	private Byte severity;
	private Byte zoom;
	private Float radius;
	private Boolean include_map;
	private ImageType image_type;
	private Integer image_height;
	private Integer image_width;
	private OutputType output;

	public TrafficBean() {
		this(false);
	}

	public TrafficBean(boolean standardInit) {
		if (standardInit) {
			setStandardValues();
		}
	}
	
	public void setStandardValues() {
		appid = "3i2ZHnvV34GdAl4rppYHsr0B1K5PpxDcznkUwc0Xqm7pJChlglFHJPIr.mfMkb4kYEA-";
		severity = 1;
		zoom = 5;
		include_map = false;
		image_type = ImageType.PNG;
		image_height = 250;
		image_width = 310;
		output = OutputType.XML;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		if (Pattern.matches("\\p{Alpha}{2}", state))
			this.state = state;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		if (Pattern.matches("\\d{5}", zip)
				|| Pattern.matches("\\d{5}-\\d{4}", zip))
			this.zip = zip;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public float getLatitude() {
		return latitude;
	}

	public void setLatitude(float latitude) {
		if (latitude >= -90 && latitude <= 90)
			this.latitude = latitude;
	}

	public float getLongtitude() {
		return longtitude;
	}

	public void setLongtitude(float longtitude) {
		if (longtitude >= -180 && longtitude <= 180)
			this.longtitude = longtitude;
	}

	public byte getSeverity() {
		return severity;
	}

	public void setSeverity(byte severity) {
		if (severity >= 1 && severity <= 5)
			this.severity = severity;
	}

	public byte getZoom() {
		return zoom;
	}

	public void setZoom(byte zoom) {
		if (zoom >= 1 && zoom <= 12)
			this.zoom = zoom;
	}

	public float getRadius() {
		return radius;
	}

	public void setRadius(float radius) {
		this.radius = radius;
	}

	public boolean isInclude_map() {
		return include_map;
	}

	public void setInclude_map(boolean includeMap) {
		include_map = includeMap;
	}

	public ImageType getImage_type() {
		return image_type;
	}

	public void setImage_type(ImageType imageType) {
		image_type = imageType;
	}

	public int getImage_height() {
		return image_height;
	}

	public void setImage_height(int imageHeight) {
		if (imageHeight >= 10 && imageHeight <= 2000)
			image_height = imageHeight;
	}

	public int getImage_width() {
		return image_width;
	}

	public void setImage_width(int imageWidth) {
		if (imageWidth >= 10 && imageWidth <= 2000)
			image_width = imageWidth;
	}

	public OutputType getOutput() {
		return output;
	}

	public void setOutput(OutputType output) {
		this.output = output;
	}

	public enum OutputType {
		XML("xml"), PHP("php");
		private String outputType;

		private OutputType(String type) {
			this.outputType = type;
		}

		public String getType() {
			return this.outputType;
		}
	}

	public enum ImageType {
		PNG("png"), GIF("gif");

		private final String type;

		private ImageType(String type) {
			this.type = type;
		}

		public String getType() {
			return this.type;
		}
	}

	public String toString() {
		StringBuffer ret = new StringBuffer("appid=");
		ret.append(appid);
		if (street != null) {
			ret.append("&street=");
			ret.append(street);
		}
		if (city != null) {
			ret.append("&city=");
			ret.append(city);
		}
		if (state != null) {
			ret.append("&state=");
			ret.append(state);
		}
		if (zip != null) {
			ret.append("&zip=");
			ret.append(zip);
		}
		if (location != null) {
			ret.append("&location=");
			ret.append(location);
		}
		if (latitude != null) {
			ret.append("&latitude=");
			ret.append(latitude);
		}
		if (longtitude != null) {
			ret.append("&longtitude=");
			ret.append(longtitude);
		}
		if (severity != null) {
			ret.append("&severity=");
			ret.append(severity);
		}
		if (zoom != null) {
			ret.append("&zoom=");
			ret.append(zoom);
		}
		if (radius != null) {
			ret.append("&radius=");
			ret.append(radius);
		}
		if (include_map != null) {
			ret.append("&include_map=");
			ret.append(include_map ? 1 : 0);
		}
		if (image_type != null) {
			ret.append("&image_type=");
			ret.append(image_type.getType());
		}
		if (image_height != null) {
			ret.append("&image_height=");
			ret.append(image_height);
		}
		if (image_width != null) {
			ret.append("&image_width=");
			ret.append(image_width);
		}
		if (output != null) {
			ret.append("&output=");
			ret.append(output.getType());
		}
		return ret.toString();
	}
}
